---
title: "Appendix: The mobilisation potential of anti-containment protests in Germany"
subtitle: Sophia Hunger, Swen Hutter, and Eylem Kanol
author: 
date: "`r Sys.Date()`"
abstract: "The Covid-19 pandemic triggered polarisation across Europe. While most citizens supported the governments’ containment measures, others took to the streets and voiced their dissatisfaction. The paper focuses on the mobilisation potential related to this het-erogenous protest wave. It examines individuals that show sympathy and are willing to engage in anti-containment demonstrations based on sixteen waves of a rolling cross-section survey fielded in Germany in 2020/2021. The results show a considerable and stable mobilisation potential: Every fifth respondent sympathises with the protesters, and around 60 percent of those are ready to participate themselves. Political distrust, far-right orientations, and an emerging ‘freedom divide’ structure the potential, as do Covid-19-related economic and health threats. Moreover, the findings indicate a radi-calisation process and show how ideology and threat perceptions drive the step from sympathy to willingness to participate, suggesting that ideological polarisation may quickly spill over to the streets given an appropriate supply of protest opportunities."
output: pdf_document
numbersections: true
toc: true
header-includes: 
  - \usepackage{booktabs}
  - \usepackage{graphicx}
  - \usepackage{placeins}
  - \usepackage{setspace}
  - \usepackage{lscape}
  - \usepackage{multirow}
  - \usepackage[T1]{fontenc}
  - \usepackage[utf8]{inputenc}
  - \usepackage{rotating, graphicx}

---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, 
                      message =FALSE, 
                      warning =FALSE,
                      cache=TRUE)

library(dplyr)
library(readxl)
library(tidyr)
library(lubridate)
library(ggplot2)
library(haven)
library(stargazer)
library(hrbrthemes)
library(kableExtra)
library(scales)
library(cowplot)
library(MASS)
library(jtools)
library(ggeffects)
library(lme4)
library(margins)
library(modelsummary)
library(sjstats)
library(viridis)
library(readr)

# define stargazer function in order to cearte tables w/ odds ratios
stargazer2 <- function(model, odd.ratio = F, ...) {
  if(!("list" %in% class(model))) model <- list(model)
    
  if (odd.ratio) {
    coefOR2 <- lapply(model, function(x) exp(coef(x)))
    seOR2 <- lapply(model, function(x) exp(coef(x)) * summary(x)$coef[, 2])
    p2 <- lapply(model, function(x) summary(x)$coefficients[, 4])
    stargazer(model, coef = coefOR2, se = seOR2, p = p2, ...)
    
  } else {
    stargazer(model, ...)
  }
}
```

```{r, eval=FALSE}

# load data with pca
mydata <- read_dta("final_data.dta") 

mydata <- mydata %>% 
  as.data.frame() %>% 
  dplyr::select(id, p1a)

# load all data 
load("final_data_v2.RData")

# combine 
df2 <- left_join(df2, mydata, by = "id")

# recode wave 
df2 <- df2 %>% 
  mutate(wave = as.factor(wave))

# recode distrust
df2 <- df2 %>% 
  mutate(trust_gov = car::recode(trust_gov, "10=0; 9=1; 8=2; 7=3; 6=4; 5=5; 4=6; 3=7; 2=8; 1=9; 0=10"))

# deal with freedomm restrictions variablen
df2 <- df2 %>% 
  mutate(parliament = as.numeric(parliament),
         privatecontact = as.numeric(privatecontact),
         publiclife = as.numeric(publiclife),
         freeassembly = as.numeric(freeassembly))


write_dta(df2,
  path="final_data_stata.dta")

df2 <- df2 %>% 
  mutate(trust_pol = case_when(v_404 == "0" ~ 99,
                                v_404 == "1 - Vertraue überhaupt nicht" ~ 10,
                                v_404 == "2" ~ 9,
                                v_404 == "3" ~ 8,
                                v_404 == "4" ~ 7,
                                v_404 == "5" ~ 6,
                                v_404 == "6" ~ 5,
                                v_404 == "7" ~ 4,
                                v_404 == "8" ~ 3,
                                v_404 == "9" ~ 2,
                                v_404 == "10 - Vertraue voll und ganz" ~ 1)) %>% 
  mutate(trust_party = case_when(v_405 == "0" ~ 99,
                                v_405 == "1 - Vertraue überhaupt nicht" ~ 10,
                                v_405 == "2" ~ 9,
                                v_405 == "3" ~ 8,
                                v_405 == "4" ~ 7,
                                v_405 == "5" ~ 6,
                                v_405 == "6" ~ 5,
                                v_405 == "7" ~ 4,
                                v_405 == "8" ~ 3,
                                v_405 == "9" ~ 2,
                                v_405 == "10 - Vertraue voll und ganz" ~ 1))


```


\newpage


```{r, eval=FALSE}


# change to sympathy
df2 <- df2 %>% 
  mutate(part_under_fact = case_when(part_under_fact == "no understand/no part" ~ "no sympathy/no part",
                                     part_under_fact == "understand/no part" ~ "sympathy/no part",
                                     part_under_fact == "understand/part" ~ "sympathy/part"))


save(df2, file="data_wep_v1.RData")

# select relevant variables
df2 <- df2 %>% 
  dplyr::select(understand_d, part_under_fact, ideology_leftright, p1a, year, month, understand_d, part_d, ideology_lr_extr, trust_gov, parliament, privatecontact, publiclife, freeassembly, health_all, eco_vul, age, age2, sex, worry_rights, worry_political, worry_social, child, marital_d, covid19, economic_situation_num, engaged_if_others, trust_soc, education, east_d, wave)

# load data
load("data_wep_v1.RData")


```

```{r}
# load data
load("data_wep_v1.RData")
```


\newpage

# Summary statistics for dependent and independent variables

```{r, results='asis', warning=FALSE, message=FALSE, echo=FALSE}

df2 %>% 
  dplyr::select(ideology_leftright, ideology_lr_extr, trust_gov, parliament, privatecontact, publiclife, freeassembly, health_all, eco_vul, age, age2, sex, child, marital_d, covid19, economic_situation_num, engaged_if_others, trust_soc, education, east_d, wave) %>% 
  mutate(gender = as.numeric(sex),
         edu2 = as.numeric(education),
         wave2 = as.numeric(wave),
         east2 = as.numeric(east_d)) %>% 
  dplyr::select(ideology_leftright, ideology_lr_extr, 
                trust_gov, parliament, privatecontact, 
                publiclife, freeassembly, health_all, 
                eco_vul, age, age2, gender, child, 
                marital_d, covid19, economic_situation_num, 
                engaged_if_others, trust_soc, edu2, east2, wave2) %>% 
  stargazer(header = FALSE,
            covariate.labels = c("Ideology left-right", "Extreme ideology", "Distrust in government", 
            "Bypassing of parliament", " Freedom of assembly", "Restrictions on private contacts", 
            "Restrictions on public life", "Health threat", "Economic threat", "Age","Age²", 
            "Female", "Children", "Married", "Infection (self or close individuals)", 
            "Economic situation", "Engaged if others", "Social trust", "Education",  
            "East Germany", "wave"),
            title="Summary statistics")


```

\newpage

# Figure 2: Development of sympathy and readiness to participate in anti-containment protests by survey wave (2020-2021)

```{r, fig.align='center', fig.show="hold", fig.cap="\\label{fig:stable}Development of support and participation over time (aggregated by wave)", fig.pos="!htp", fig.width=8}

# make proper month variable
df2 <- df2 %>% 
  mutate(ym =  as.character(zoo::as.yearmon(paste(year, month), "%Y %m")))

# summarize by wave
df_agg <- df2 %>% 
  drop_na(part_under_fact) %>% 
  mutate(count1 = 1) %>% 
  group_by(wave, part_under_fact) %>% 
 summarise(percentage=n()) %>% 
 group_by(wave) %>% 
 mutate(percentage=percentage/sum(percentage)*100) %>% 
  ungroup()


df_agg2 <- df_agg %>% 
  mutate(wave = as.numeric(as.character(wave))) %>% 
  mutate(wave2 = case_when(wave > 14 ~ as.numeric(wave)+4,
                           TRUE ~ wave)) %>% 
  dplyr::select(wave2, part_under_fact, percentage)

# add empty observations

vect1 <- c(14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17)

vect2 <- c("no sympathy/no part", "sympathy/no part", "sympathy/part",
           "no sympathy/no part", "sympathy/no part", "sympathy/part",
           "no sympathy/no part", "sympathy/no part", "sympathy/part",
           "no sympathy/no part", "sympathy/no part", "sympathy/part"
           )

vect3 <- c(NA, NA, NA,
           NA, NA, NA,
           NA, NA, NA,
           NA, NA, NA
           )

df_add <- cbind.data.frame(vect1, vect2, vect3)

colnames(df_add) <- c("wave2", "part_under_fact", "percentage")

df_agg3 <- rbind.data.frame(df_agg2, df_add)


ggplot(df_agg3, aes(x=as.numeric(wave2), y=percentage, fill=factor(part_under_fact))) + 
    geom_area(alpha=0.6 , size=.5, colour="white",
              position = position_stack(reverse = TRUE)) +
    scale_fill_viridis(discrete = T)   +
    ylab("percent of respondents") +
    xlab("") +
    labs(fill = "") + 
    theme(axis.text.x=element_text(angle=45, vjust=.5), 
          axis.title.y = element_text(size=12)) +
  scale_fill_manual(values = c("grey10","grey50","grey80"))  +
  scale_x_continuous(breaks=c(8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27), 
                     labels=c("June(1)", "June(2)", "July(1)", "July(2)", "August(1)", "August(2)", "", "", "", "", "November(1)", "November(2)", "December(1)", "December(2)", "January(1)", "January(2)", "February(1)", "March(1)", "March(2)", "April(1)"))

```



\newpage 

# Figure 3: Share of groups by respondents’ attitude



```{r}

avg_understand <- df2 %>% 
  dplyr::filter(!(understand_d == 0 & part_d ==1)) %>% 
  dplyr::select(understand_d) %>% 
  mutate(understand_d2 = as.numeric(as.character(understand_d)))

# make less fine grained left-right variable

p1 <- df2 %>%
  dplyr::filter(!(understand_d == 0 & part_d ==1)) %>% 
  mutate(support_fact = case_when(understand_d == 0 ~ "no sympathy",
                                  understand_d == 1 ~ "sympathy")) %>% 
  count(ideology_leftright, support_fact) %>%
  ggplot(aes(x = ideology_leftright, y = n, fill = support_fact)) + 
  geom_col(color = "white", position = position_fill(reverse = FALSE), width=1) + 
       labs(title = "Sympathy", x="") +
  geom_hline(yintercept = mean(avg_understand$understand_d2), linetype='dotted', col = 'red', size=1,5) +
  scale_fill_manual(values = c("sympathy"="grey10","no sympathy"="grey80")) +
  scale_y_continuous(labels = scales::comma) +
  coord_flip() + 
  theme_minimal(base_size = 12) +
  theme(legend.position="bottom") +
  guides(fill=guide_legend(nrow=2,byrow=TRUE))  + 
  scale_x_continuous(name ="Ideology", 
                     breaks = c(0,1,2,3,4,5,6,7,8,9,10)) +
  scale_y_continuous(name="")


avg_part <- df2 %>% 
  dplyr::filter(understand_d == 1) %>% 
  dplyr::select(part_d) %>% 
  mutate(part_d2 = as.numeric(as.character(part_d))) 

p2 <- df2 %>%
  dplyr::filter(understand_d == 1) %>% 
  mutate(participate_fact = as.factor(case_when(part_d == 0 ~ "not willing to protest",
                                  part_d == 1 ~ "willing to protest"))) %>% 
  count(ideology_leftright, participate_fact) %>%
  ggplot(aes(x = ideology_leftright, y = n, fill = participate_fact)) + 
  geom_col(color = "white", position = position_fill(reverse = FALSE), width=1) + 
  labs(title = "Willing to participate", x="") +
  geom_hline(yintercept = mean(as.numeric(avg_part$part_d2)), linetype='dotted', col = 'red', size=1,5) +
  scale_fill_manual(values = c("willing to protest"="grey10","not willing to protest"="grey80")) +
  scale_y_continuous(labels = scales::comma, name="") +
  coord_flip() + 
  theme_minimal(base_size = 12) +
  theme(legend.position="bottom") +
  guides(fill=guide_legend(nrow=2,byrow=TRUE)) + 
  scale_x_continuous(name ="Ideology", 
                     breaks = c(0,1,2,3,4,5,6,7,8,9,10)) 

```


```{r}
p3 <- df2 %>%
  dplyr::filter(!(understand_d == 0 & part_d ==1)) %>% 
  mutate(support_fact = case_when(understand_d == 0 ~ "no sympathy",
                                  understand_d == 1 ~ "sympathy")) %>% 
  count(trust_gov, support_fact) %>%
  ggplot(aes(x = trust_gov, y = n, fill = support_fact)) + 
  geom_col(color = "white", position = position_fill(reverse = FALSE), width=1) + 
  labs(x = "") +
  geom_hline(yintercept = mean(avg_understand$understand_d2), linetype='dotted', col = 'red', size=1,5) +
  scale_fill_manual(values = c("sympathy"="grey10","no sympathy"="grey80")) +
  scale_y_continuous(labels = scales::comma) +
  coord_flip() + 
  theme_minimal(base_size = 12) +
  theme(legend.position="bottom") +
  guides(fill=guide_legend(nrow=2,byrow=TRUE))  + 
  scale_x_continuous(name ="Distrust in gov.", 
                     breaks = c(0,1,2,3,4,5,6,7,8,9,10)) + 
  scale_y_continuous(name="")



p4 <- df2 %>%
  dplyr::filter(understand_d == 1) %>% 
  mutate(participate_fact = as.factor(case_when(part_d == 0 ~ "not willing to protest",
                                  part_d == 1 ~ "willing to protest"))) %>% 
  count(trust_gov, participate_fact) %>%
  ggplot(aes(x = trust_gov, y = n, fill = participate_fact)) + 
  geom_col(color = "white", position = position_fill(reverse = FALSE), width=1) + 
  labs(x = "") + 
  geom_hline(yintercept = mean(as.numeric(avg_part$part_d2)), linetype='dotted', col = 'red', size=1,5) +
  scale_fill_manual(values = c("willing to protest"="grey10","not willing to protest"="grey80")) +
  scale_y_continuous(labels = scales::comma) +
  coord_flip() + 
  theme_minimal(base_size = 12) +
  theme(legend.position="bottom") +
  guides(fill=guide_legend(nrow=2,byrow=TRUE)) + 
  scale_x_continuous(name ="Distrust in gov.", 
                     breaks = c(0,1,2,3,4,5,6,7,8,9,10))  +
  scale_y_continuous(name="")


```


```{r}

# new average because different sample
avg_understand <- df2 %>% 
  dplyr::filter(!(understand_d == 0 & part_d ==1)) %>% 
  dplyr::filter(!is.na(worry_rights)) %>% 
  dplyr::select(understand_d) %>% 
  mutate(understand_d2 = as.numeric(as.character(understand_d)))



p5 <- df2 %>%
  dplyr::filter(!(understand_d == 0 & part_d ==1)) %>% 
  dplyr::filter(!is.na(worry_rights)) %>% 
  mutate(support_fact = case_when(understand_d == 0 ~ "no sympathy",
                                  understand_d == 1 ~ "sympathy")) %>% 
  count(worry_political, support_fact) %>%
  ggplot(aes(x = worry_political, y = n, fill = support_fact)) + 
  geom_col(color = "white", position = position_fill(reverse = FALSE), width=1) + 
  labs(x = "", 
       fill = "Share of supporters") +
  geom_hline(yintercept = mean(avg_understand$understand_d2), linetype='dotted', col = 'red', size=1,5) +
  scale_fill_manual(values = c("sympathy"="grey10","no sympathy"="grey80")) +
  scale_y_continuous(labels = scales::comma) +
  coord_flip() + 
  theme_minimal(base_size = 12) +
  theme(legend.position="bottom") +
  guides(fill=guide_legend(nrow=2,byrow=TRUE)) + 
  scale_x_continuous(name ="Worry political", 
                      breaks = c(1,2,3,4,5)) + 
  scale_y_continuous(name="")


# new average bc different subsample
avg_part <- df2 %>% 
  dplyr::filter(understand_d == 1) %>% 
  dplyr::filter(!is.na(worry_rights)) %>% 
  dplyr::select(part_d) %>% 
  mutate(part_d2 = as.numeric(as.character(part_d))) 



p6 <- df2 %>%
  dplyr::filter(understand_d == 1) %>% 
  mutate(participate_fact = as.factor(case_when(part_d == 0 ~ "not willing to protest",
                                  part_d == 1 ~ "willing to protest"))) %>% 
  count(worry_political, participate_fact) %>%
  ggplot(aes(x = worry_political, y = n, fill = participate_fact)) + 
  geom_col(color = "white", position = position_fill(reverse = FALSE), width=1) + 
  labs(x = "", 
       fill = "Share of participants") +
  geom_hline(yintercept = mean(as.numeric(avg_part$part_d2)), linetype='dotted', col = 'red', size=1,5) +
  scale_fill_manual(values = c("willing to protest"="grey10","not willing to protest"="grey80")) +
  scale_y_continuous(labels = scales::comma) +
  coord_flip() + 
  theme_minimal(base_size = 12) +
  theme(legend.position="bottom") +
  guides(fill=guide_legend(nrow=2,byrow=TRUE)) + 
  scale_x_continuous(name ="Worry political", 
                      breaks = c(1,2,3,4,5)) + 
  scale_y_continuous(name="")


```



```{r}

# new average because different sample
avg_understand <- df2 %>% 
  dplyr::filter(!(understand_d == 0 & part_d ==1)) %>% 
  dplyr::filter(!is.na(worry_rights)) %>% 
  dplyr::select(understand_d) %>% 
  mutate(understand_d2 = as.numeric(as.character(understand_d)))



p7 <- df2 %>%
  dplyr::filter(!(understand_d == 0 & part_d ==1)) %>% 
  dplyr::filter(!is.na(worry_rights)) %>% 
  mutate(support_fact = case_when(understand_d == 0 ~ "no sympathy",
                                  understand_d == 1 ~ "sympathy")) %>% 
  count(worry_social, support_fact) %>%
  ggplot(aes(x = worry_social, y = n, fill = support_fact)) + 
  geom_col(color = "white", position = position_fill(reverse = FALSE), width=1) + 
  labs(x = "", 
       fill = "Share of supporters") +
  geom_hline(yintercept = mean(avg_understand$understand_d2), linetype='dotted', col = 'red', size=1,5) +
  scale_fill_manual(values = c("sympathy"="grey10","no sympathy"="grey80")) +
  scale_y_continuous(labels = scales::comma) +
  coord_flip() + 
  theme_minimal(base_size = 12) +
  theme(legend.position="bottom") +
  guides(fill=guide_legend(nrow=2,byrow=TRUE)) + 
  scale_x_continuous(name ="Worry social", 
                      breaks = c(1,2,3,4,5)) + 
  scale_y_continuous(name="")


# new average bc different subsample
avg_part <- df2 %>% 
  dplyr::filter(understand_d == 1) %>% 
  dplyr::filter(!is.na(worry_rights)) %>% 
  dplyr::select(part_d) %>% 
  mutate(part_d2 = as.numeric(as.character(part_d))) 



p8 <- df2 %>%
  dplyr::filter(understand_d == 1) %>% 
  mutate(participate_fact = as.factor(case_when(part_d == 0 ~ "not willing to protest",
                                  part_d == 1 ~ "willing to protest"))) %>% 
  count(worry_social, participate_fact) %>%
  ggplot(aes(x = worry_social, y = n, fill = participate_fact)) + 
  geom_col(color = "white", position = position_fill(reverse = FALSE), width=1) + 
  labs(x = "", 
       fill = "Share of participants") +
  geom_hline(yintercept = mean(as.numeric(avg_part$part_d2)), linetype='dotted', col = 'red', size=1,5) +
  scale_fill_manual(values = c("willing to protest"="grey10","not willing to protest"="grey80")) +
  scale_y_continuous(labels = scales::comma) +
  coord_flip() + 
  theme_minimal(base_size = 12) +
  theme(legend.position="bottom") +
  guides(fill=guide_legend(nrow=2,byrow=TRUE)) + 
  scale_x_continuous(name ="Worry social", 
                      breaks = c(1,2,3,4,5)) + 
  scale_y_continuous(name="")


```

\FloatBarrier

\newpage

```{r, fig.align='center', fig.show="hold", fig.cap="\\label{fig:groups}Share of groups by resondents' ideology", fig.pos="!htp", fig.width=7, fig.height=10}


plots <- cowplot::plot_grid(p1+theme(legend.position="none"), 
                   p2+theme(legend.position="none"), 
                   p3+theme(legend.position="none"), 
                   p4+theme(legend.position="none"), 
                   p5+theme(legend.position="none"), 
                   p6+theme(legend.position="none"), 
                   p7+theme(legend.position="none"), 
                   p8+theme(legend.position="none"),
                   labels = c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'), 
                   label_size = 12, 
                   nrow = 4)


legend1 <- get_legend(
  # create some space to the left of the legend
  p1 + theme(legend.box.margin = margin(0, 0, 0, 12)) + guides(fill=guide_legend("Share of respondents", nrow=2))
)

legend2 <- get_legend(
  # create some space to the left of the legend
  p2 + theme(legend.box.margin = margin(0, 0, 0, 12)) + guides(fill=guide_legend("Share of understander", nrow=2))
)

# bind legends
legends <- cowplot::plot_grid(legend1, legend2, nrow=1)

# final plot
cowplot::plot_grid(plots, legends, nrow=2, rel_heights = c(10, 1))


```

\FloatBarrier

# Main models 

## Figure 4: Average marginal effects of logistic regression models predicting sympathy for and willingness to participate in anti-containment protests


```{r}

# create subsamples (only vars of interest, in order to avoid clashes with margins-package)
df3 <- df2 %>% dplyr::select(understand_d, ideology_leftright, ideology_lr_extr, trust_gov, health_all, eco_vul, age, age2, child, marital_d, covid19, engaged_if_others, trust_soc, sex, education, economic_situation_num, east_d, wave, part_d, p1a)

# run models
mod1 <- glm(understand_d ~ ideology_leftright + ideology_lr_extr + trust_gov + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df3, family = "binomial")

mod2 <- glm(part_d ~ understand_d + ideology_leftright + ideology_lr_extr + trust_gov + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df3, family = "binomial")

# create subsample
df4 <- df3
df4$wave <- as.numeric(as.character(df3$wave))
df4 <- filter(df4, wave >= 14)
df4$wave <- as.factor(df4$wave)

# 
mod3 <- glm(understand_d ~ ideology_leftright + ideology_lr_extr + p1a + trust_gov + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df4, family = "binomial")

#
mod4 <- glm(part_d ~ understand_d + ideology_leftright + ideology_lr_extr + trust_gov + p1a + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df4, family = "binomial")


```

```{r}

# Prepare models for plotting
mod1margs <- summary(margins(mod1))
mod2margs <- summary(margins(mod2))
mod3margs <- summary(margins(mod3))
mod4margs <- summary(margins(mod4))

mod1margs_df <- as.data.frame(mod1margs)
mod2margs_df <- as.data.frame(mod2margs)
mod3margs_df <- as.data.frame(mod3margs)
mod4margs_df <- as.data.frame(mod4margs)

mod1margs_df$group <- rep("sympathy", 32)
mod2margs_df$group <- rep("willing to part.", 33)
mod3margs_df$group <- rep("sympathy", 27)
mod4margs_df$group <- rep("willing to part.", 28)

mod1margs_df$model <- rep("model1", 32)
mod2margs_df$model <- rep("model2", 33)
mod3margs_df$model <- rep("model3", 27)
mod4margs_df$model <- rep("model4", 28)

margin_df <- rbind(mod1margs_df, mod2margs_df, mod3margs_df, mod4margs_df)

margin_df <-filter(margin_df, factor == "understand_d" | 
                                   factor == "ideology_leftright" | 
                                   factor == "ideology_lr_extr" | 
                                   factor == "trust_gov" | 
                                   factor == "health_all" | 
                                   factor == "eco_vul" | 
                                   factor == "p1a")


margin_df <- margin_df %>% 
  mutate(factor = case_when(factor == "ideology_leftright" ~ "Ideology",
                            factor == "ideology_lr_extr" ~ "Extreme ideology",
                            factor == "trust_gov" ~ "Distrust in government",
                            factor == "health_all" ~ "Health threat",
                            factor == "eco_vul" ~ "Economic threat",
                            factor == "p1a" ~ "Freedom restrictions")) %>% 
  mutate(factor = ordered(factor, levels = c("Economic threat",  "Health threat", "Freedom restrictions", "Distrust in government", "Extreme ideology", "Ideology")))

g1 <- ggplot(margin_df, aes(AME, factor, group = model, shape=model)) + facet_grid( ~ group) + 
        geom_errorbar(aes(xmax = AME + 1.96*SE, xmin = AME - 1.96*SE),
                      width = 0, position = position_dodge(width = 0.4)) +
        geom_point(aes(), position = position_dodge(width = 0.4), size = 3) +
  geom_vline(xintercept = 0, linetype="dashed", color="gray60") +
  theme(legend.position = "none",axis.title.y = element_blank()) +
  ylab("") +
  theme_bw()


g1


```

\newpage

## Regression tables for main models

```{r}

mod1_margins <- margins(mod1)
mod2_margins <- margins(mod2)
mod3_margins <- margins(mod3)
mod4_margins <- margins(mod4)


models_out <- list(
  "Sympathy" =  mod1_margins,
  "Willingness" =  mod2_margins,
  "Sympathy" =  mod3_margins,
  "Willingness" =  mod4_margins)

modelsummary(models_out, 
             coef_rename = c("understand_d1" = "Symapthy", "ideology_leftright" = "Ideology left-right", 
                             "ideology_lr_extr" = "Extreme ideology", "trust_gov" = "Distrust in government", 
                             "p1a" = "Freedom restrictions", "health_all" = "Health threat", 
                             "eco_vul" = "Economic threat", "age" = "Age", "age2" = "Age squ.",  
                             "child" = "Children", "marital_d" = "Married", "understand_d" = "Sympathy", 
                             "covid19" = "Infection (self or close individuals)", 
                             "engaged_if_others" = "Engaged if others", "east_d" = "East Germany", 
                             "trust_soc" = "Social trust", "sexFemale" = "Female", 
                             "educationmiddel" = "Education - middle", 
                             "educationhigh" = "Education - high", 
                             "economic_situation_num" = "Economic situation"),
             stars = TRUE, 
             coef_omit = "wave*",
             output = "markdown")

```




```{r, results='asis', warning=FALSE, message=FALSE, echo=FALSE, eval=FALSE}

model_list <- list(mod1, mod2, mod3, mod4)

stargazer2(model_list,
          type="latex",
          single.row = T,
          digits=2,
          odd.ratio = T,digits.extra = 0,
          title="Main: Models: Regression Results (odds ratios)",
          column.sep.width = "5pt",
          covariate.labels=c("Sympathy", "Ideology left-right", 
                             "Extreme ideology", "Distrust in government", 
                             "Freedom restrictions", "Health threat", "Economic threat", 
                             "Age","Age²", "Children",  "Married", 
                             "Infection (self or close individuals)", 
                             "Engaged if others", "Social trust", "Female",
                             "Education - middle", "Education - high", 
                             "Economic situation", "East Germany"),
          dep.var.labels = c("symapthy", "participate", "sympathy", "participate"),
          star.char = c("*", "**", "***"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          notes = c("* p<0.05; ** p<0.01; *** p<0.001"),
          header = FALSE,
          notes.append = F,
          omit = c("wave9", "wave10", "wave11", "wave12", "wave13", "wave14", "wave15", "wave16", "wave17", "wave18", "wave19", "wave20","wave21", "wave22","wave23"),
          order=paste0("^", vars.order , "$"),
          out = "mainmodels_new_or_alt.doc")


```




\newpage


# Robustness check: Include worry variables individually


```{r}
# stepwise inclusion of worry variables

# assembly 
m7 <- glm(understand_d ~ ideology_leftright + ideology_lr_extr + trust_gov + freeassembly + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")

m8 <- glm(part_d ~ understand_d + ideology_leftright + ideology_lr_extr + trust_gov + freeassembly + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")

# parliament
m9 <- glm(understand_d ~ ideology_leftright + ideology_lr_extr + trust_gov + parliament + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")

m10 <- glm(part_d ~ understand_d + ideology_leftright + ideology_lr_extr + trust_gov + parliament + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")

# publiclife
m11 <- glm(understand_d ~ ideology_leftright + ideology_lr_extr + trust_gov + publiclife + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")

m12 <- glm(part_d ~ understand_d + ideology_leftright + ideology_lr_extr + trust_gov + publiclife + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")

# privatecontact
m13 <- glm(understand_d ~ ideology_leftright + ideology_lr_extr + trust_gov + privatecontact + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")

m14 <- glm(part_d ~ understand_d + ideology_leftright + ideology_lr_extr + trust_gov + privatecontact + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")


vars.order <- c("understand_d1", "ideology_leftright", "ideology_lr_extr", "trust_gov", "freeassembly", "parliament", "publiclife",  "privatecontact", "health_all", "eco_vul", "age", "age2", "child", "marital_d", "covid19", "engaged_if_others", "trust_soc", "sexFemale", "educationmiddel", "educationhigh", "economic_situation_num", "east_d")

```


\tiny

```{r, results='asis', warning=FALSE, message=FALSE, echo=FALSE}

model_list <- list(m7, m8, m9, m10, m11, m12, m13, m14)

stargazer2(model_list,
          type="latex",
          single.row = T,
          digits=2,
          odd.ratio = T,
          digits.extra = 0,
          title="Regression Results for individual freedom restrictions variables (odds)",
          column.sep.width = "5pt",
          covariate.labels=c("Sympathy", "Ideology left-right", "Extreme ideology", 
                             "Distrust in gov.", "freeassembly", "parliament", "publiclife",  
                             "privatecontact",  "Health threat", "Economic threat", "Age","Age²", 
                             "Children",  "Married", "Infection", "Engaged if others", 
                             "Social trust", "Female",  "Education - middle", "Education - high", 
                             "Economic situation", "East Germany"),
          dep.var.labels = c("sympathy", "participate", "sympathy", "participate", "sympathy", "participate", "sympathy", "participate"),
          star.char = c("*", "**", "***"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          omit = c("wave15", "wave16", "wave17", "wave18", "wave19", "wave20","wave21", "wave22","wave23"),
          notes = c("* p<0.05; ** p<0.01; *** p<0.001"),
          header = FALSE,
          notes.append = F,
          order=paste0("^", vars.order , "$"),
          float.env = "sidewaystable")


```


\normalsize


\newpage


# Interactions for different time periods

Lastly, we interact the two main periods of the time frame under analysis with our main explanatory variables: ideology, extreme ideology, trust in government, economic and health risks. The interactions for ideology and trust in government are included in the main paper. The interactions plots for extreme ideology as well as economic and health threats can be found below. We consider two main splits within our time frame: before August 2020, after August 2020 and observations in the year 2021. The first split is marked by large protests in several German cities. These protests received a lot of public and media attention due to several radical and violent action forms, most notably when demonstrators tried to enter the parliamentary building of the German Bundestag. The split between fall 2020 and spring 2021 is characterized by the further radicalization and two lockdowns. This allows us to test the consistency of our findings against the dynamically evolving situation of the protests. We find several differences in the driving factors of protest support and willingness to participate between the three time periods. 

## Figure 5: Average marginal effects of left–right ideology and trust in government conditional on time


```{r}

# calculate AMES

df2 <- df2 %>% 
  mutate(period = as.factor(case_when(month < 8 & year ==2020 ~ "pre August 2020",
                                      month >= 8 & year == 2020 ~ "post August",
                             TRUE ~ "2021")))

df2$period <- ordered(df2$period, levels = c("pre August 2020", "post August", "2021"))


# subsetting the DF and removing all other variables seems to solve the problem with margins package
df3 <- df2 %>% dplyr::select(understand_d, ideology_leftright, ideology_lr_extr, trust_gov, health_all, eco_vul, age, age2, child, marital_d, covid19, engaged_if_others, trust_soc, sex, education, economic_situation_num, east_d, wave, part_d, p1a, period)
  

#############################
# ideology and trust
############################

mod1 <- glm(understand_d ~ period/ideology_leftright + ideology_lr_extr + trust_gov +health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d, data = df3, family = "binomial")

mod2 <- glm(understand_d ~ ideology_leftright + ideology_lr_extr + period/trust_gov +health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d, data = df3, family = "binomial")

mod3 <- glm(part_d ~ period/ideology_leftright + ideology_lr_extr + understand_d + trust_gov +health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d, data = df3, family = "binomial")

mod4 <- glm(part_d ~ ideology_leftright + ideology_lr_extr + understand_d + period/trust_gov +health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d, data = df3, family = "binomial")



###################################
# from: https://grantmcdermott.com/interaction-effects/


dict1 = c('period2021:ideology_leftright' = '2021', 
          'periodpost August:ideology_leftright' = 'post-August 2020',
          'periodpre August 2020:ideology_leftright' = 'pre-August 2020'
         )

p1 <- modelplot(mod1, coef_map = dict1) +
  geom_vline(xintercept = 0, col = "orange") +
  labs(
    x = "Marginal effect",
    title = "", 
    subtitle = "AME of ideology on sympathy"
    ) 

p3 <- modelplot(mod3, coef_map = dict1) +
  geom_vline(xintercept = 0, col = "orange") +
  labs(
    x = "Marginal effect",
    title = "", 
    subtitle = "AME of ideology on willingness"
    ) 


###################################

dict2 <- c('period2021:trust_gov' = '2021', 
           'periodpost August:trust_gov' = 'post-August 2020',
           'periodpre August 2020:trust_gov' = 'pre-August 2020')


p2 <- modelplot(mod2, coef_map = dict2) +
  geom_vline(xintercept = 0, col = "orange") +
  labs(
    x = "Marginal effect",
    title = "", 
    subtitle = "AME of trust on sympathy"
    ) 

p4 <- modelplot(mod4, coef_map = dict2) +
  geom_vline(xintercept = 0, col = "orange") +
  labs(
    x = "Marginal effect",
    title = "", 
    subtitle = "AME of trust on willingness"
    ) 


period_effects <- cowplot::plot_grid(p1, p3, p2, p4)

period_effects

```







\newpage

## Regression table for models in figure 5, main text

```{r}


models_out <- list(
  "Sympathy" =  mod1,
  "Sympathy" =  mod2,
  "Willingness" =  mod3,
  "Willingness" =  mod4)

modelsummary::modelsummary(models_out, 
                           coef_rename = c("understand_d1" = "Sympathy", 
                                           "ideology_leftright" = "Ideology left-right", 
                                           "period.L" = "post. Aug 2020",
                                           "period.Q" = "2021",
                                           "periodpre August 2020:ideology_leftright" = "pre Aug. 2020*ideology", 
                                           "periodpost August:ideology_leftright" = "post. Aug. 2020*ideology",
                                           "period2021:ideology_leftright" = "2021*ideology",
                                           "periodpre August 2020:trust_gov" = "pre Aug. 2020* trust in gov.", 
                                           "periodpost August:trust_gov" = "post. Aug. 2020*trust in gov.",
                                           "period2021:trust_gov" = "2021*trust in gov.",
                                           "ideology_lr_extr" = "Extreme ideology",
                                           "trust_gov" = "Distrust in government", 
                                           "p1a" = "Freedom restrictions", 
                                           "health_all" = "Health threat",
                                           "eco_vul" = "Economic threat", 
                                           "age" = "Age", "age2" = "Age squ.", 
                                           "child" = "Children", "marital_d" = "Married", 
                                           "understand_d" = "Sympathy", 
                                           "covid19" = "Infection (self or close individuals)", 
                                           "engaged_if_others" = "Engaged if others", 
                                           "east_d" = "East Germany", 
                                           "trust_soc" = "Social trust", 
                                           "sexFemale" = "Female", 
                                           "educationmiddel" = "Education - middle", 
                                           "educationhigh" = "Education - high", 
                                           "economic_situation_num" = "Economic situation"),
                           stars = TRUE, 
                           coef_omit = "wave*", 
                           output = "markdown")

```

\newpage


## Extreme ideology as well as economic and health threat over time


```{r}
#################################
# Sympathy


#################################
# ideology extreme
#################################

mod1 <- glm(understand_d ~ ideology_leftright + period/ideology_lr_extr + trust_gov +health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d, data = df3, family = "binomial")


#################################
# eco threat
#################################

mod2 <- glm(understand_d ~ ideology_leftright + ideology_lr_extr + trust_gov +health_all + period/eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d, data = df3, family = "binomial")

#################################
# health threat
#################################

mod3 <- glm(understand_d ~ ideology_leftright + ideology_lr_extr + trust_gov +period/health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d, data = df3, family = "binomial")


```

```{r}
########
# WILLIGNESS TO PArTICIPATE


###########################
# extreme ideology
###########################

mod4 <- glm(part_d ~ ideology_leftright + period/ideology_lr_extr + understand_d + trust_gov +health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d, data = df3, family = "binomial")

###########################
# eco threat
###########################

mod5 <- glm(part_d ~ ideology_leftright + ideology_lr_extr + understand_d + trust_gov +health_all + period/eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d, data = df3, family = "binomial")

###########################
# eco threat
###########################

mod6 <- glm(part_d ~ ideology_leftright + ideology_lr_extr + understand_d + trust_gov +period/health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d, data = df3, family = "binomial")

```



```{r, eval=TRUE}

###########################
# plots for extreme ideology
###########################

dict1 = c('period2021:ideology_lr_extr' = '2021', 
          'periodpost August:ideology_lr_extr' = 'post-August 2020',
          'periodpre August 2020:ideology_lr_extr' = 'pre-August 2020'
         )

p1 <- modelplot(mod1, coef_map = dict1) +
  geom_vline(xintercept = 0, col = "orange") +
  labs(
    x = "Marginal effect",
    title = "", 
    subtitle = "AME of extr. ideology on sympathy"
    ) 

p4 <- modelplot(mod4, coef_map = dict1) +
  geom_vline(xintercept = 0, col = "orange") +
  labs(
    x = "Marginal effect",
    title = "", 
    subtitle = "AME of extr. ideology on willingness"
    ) 


##########################
# plots for eco threat
########################


dict2 = c('period2021:eco_vul' = '2021', 
          'periodpost August:eco_vul' = 'post-August 2020',
          'periodpre August 2020:eco_vul' = 'pre-August 2020'
         )

p2 <- modelplot(mod2, coef_map = dict2) +
  geom_vline(xintercept = 0, col = "orange") +
  labs(
    x = "Marginal effect",
    title = "", 
    subtitle = "AME of eco. threat on sympathy"
    ) 

p5 <- modelplot(mod5, coef_map = dict2) +
  geom_vline(xintercept = 0, col = "orange") +
  labs(
    x = "Marginal effect",
    title = "", 
    subtitle = "AME of eco. threat on willingness"
    ) 

##########################
# plots for health threat
##########################


dict3 = c('period2021:health_all' = '2021', 
          'periodpost August:health_all' = 'post-August 2020',
          'periodpre August 2020:health_all' = 'pre-August 2020'
         )

p3 <- modelplot(mod3, coef_map = dict3) +
  geom_vline(xintercept = 0, col = "orange") +
  labs(
    x = "Marginal effect",
    title = "", 
    subtitle = "AME of health threat on sympathy"
    ) 

p6 <- modelplot(mod6, coef_map = dict3) +
  geom_vline(xintercept = 0, col = "orange") +
  labs(
    x = "Marginal effect",
    title = "", 
    subtitle = "AME of health threat on willingness"
    ) 


#######################
# combine 
#######################

cowplot::plot_grid(p1, p4, p2, p5, p3, p6, ncol = 2)


```



\begin{landscape}

\begin{figure}[htbp]
\includegraphics{period_effects_appendix.pdf}
\caption{Period effects}
\label{fig}
\end{figure}



\end{landscape}

\newpage



## Regression tables for extreme ideology and economic and health threat over time 


```{r}


models_out <- list(
  "Sympathy" =  mod1,
  "Symapthy" =  mod2,
  "Sympathy" =  mod3,
  "Willingness" =  mod4,
  "Willingness" =  mod5,
  "Willingness" =  mod6)


```



```{r, results='asis'}
stargazer2(models_out,
          type="latex",
          single.row =TRUE,
          float.env = "sidewaystable",
          no.space = TRUE,
          digits=2,
          odd.ratio = T,
          digits.extra = 0,
          title="Regression Results (odds ratios)",
          column.sep.width = "5pt",
          covariate.labels=c("Sympathy", "Ideology left-right", "Extreme ideology", "Distrust gov.", "Health threat", "Economic threat", "Age","Age²", "Children",  "Married", "Infection (self or close individuals)", "Engaged if others", "Social trust", "Female",  "Education - middle", "Education - high", "Economic situation", "East Germany", "post August", "2021", "post Aug.*extreme ideol.", "2021*extreme ideol.", "post Aug.*eco. vul.", "2021.*eco. vul.", "post Aug.*health",  "2021*health"),
          dep.var.labels = c("sympathy","willingness"),
          star.char = c("*", "**", "***"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          notes = c("* p<0.05; ** p<0.01; *** p<0.001"),
          omit = c("wave9", "wave10", "wave11", "wave12", "wave13", "wave14", "wave15", "wave16", "wave17", "wave18", "wave19", "wave20","wave21", "wave22","wave23"),
          header = FALSE,
          notes.append = F,
          order=paste0("^", vars.order , "$")
          )
```

\newpage

# Robustness check: Curvilinear term for ideology


```{r}

df2 <- df2 %>% 
  mutate(ideol_sq = ideology_leftright^2)
  
# make models with other trust var
m1<- glm(understand_d ~ ideology_leftright + I(ideology_leftright^2) + trust_gov + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")

m2<- glm(part_d ~ understand_d + ideology_leftright +  I(ideology_leftright^2) + trust_gov +health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")

m3<- glm(understand_d ~ ideology_leftright +  I(ideology_leftright^2) + trust_gov + p1a + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")

m4<- glm(part_d ~ understand_d + ideology_leftright + I(ideology_leftright^2) + trust_gov + p1a + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")

# correct order for regression table
vars.order <- c("understand_d1", "ideology_leftright", "ideol_sq", "trust_gov", "p1a", "health_all", "eco_vul", "age", "age2", "child", "marital_d", "covid19", "engaged_if_others", "trust_soc", "sexFemale", "educationmiddel", "educationhigh", "economic_situation_num", "east_d")

```

```{r, results='asis', warning=FALSE, message=FALSE}

model_list <- list(m1, m2, m3, m4)

stargazer2(model_list,
          type="latex",
          single.row = T,
          digits=2,
          odd.ratio = T,
          digits.extra = 0,
          title="Regression Results (odds ratios)",
          column.sep.width = "5pt",
          covariate.labels=c("Sympathy", "Ideology left-right", "Ideology squared", "Distrust in government", "freedom restrictions", "Health threat", "Economic threat", "Age","Age²", "Children",  "Married", "Infection (self or close individuals)","Engaged if others", "Social trust", "Female",   "Education - middle", "Education - high", "Economic situation", "East Germany"),
          dep.var.labels = c("support", "participate", "support", "participate"),
          star.char = c("*", "**", "***"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          notes = c("* p<0.05; ** p<0.01; *** p<0.001"),
          omit = c("wave9", "wave10", "wave11", "wave12", "wave13", "wave14", "wave15", "wave16", "wave17", "wave18", "wave19", "wave20","wave21", "wave22","wave23"),
          header = FALSE,
          notes.append = F,
          order=paste0("^", vars.order , "$"),
          out = "mainmodels_ideolog.doc")
```

```{r, message=FALSE, warning=FALSE, fig.align='center', fig.show="hold", fig.cap="\\label{fig:curvi1}Predicted probabilities for sympathy", fig.pos="!htp", fig.width=7, fig.height=4}


m1_m <- ggeffect(m1, c("ideology_leftright"))
plot(m1_m) +
  labs(
    x = "Ideology", 
    y = "sympathy", 
    title = ""
  )


```

```{r, message=FALSE, warning=FALSE, fig.align='center', fig.show="hold", fig.cap="\\label{fig:curvi2}Predicted probabilities for willigness to protest", fig.pos="!htp", fig.width=7, fig.height=4}


m2_m <- ggeffect(m2, c("ideology_leftright"))

plot(m2_m) +
  labs(
    x = "Ideology", 
    y = "willingess to protest", 
    title = ""
  )

```

\newpage


# Robustness check: Political trust

Since most of our data includes a measure of political trust that is closely related to the pandemic, we perform additional robustness checks using two items that asks for distrust in politicians and political parties, which were, however, only included on the later waves. The models below show that the results are consistent with our main models regarding sympathy for the anti-containment protest (model 1 and 3 in table 7). For willingness to participate, the significance, however, vanishes (model 2 and 4). 


```{r}

# make models with other trust var

m1<- glm(understand_d ~ ideology_leftright + ideology_lr_extr + trust_pol + p1a +  health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")
# 
m2<- glm(part_d ~ understand_d + ideology_leftright + ideology_lr_extr + trust_pol + p1a + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")
#
m3<- glm(understand_d ~ ideology_leftright + ideology_lr_extr + trust_party + p1a + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")
#
m4<- glm(part_d ~ understand_d + ideology_leftright + ideology_lr_extr + trust_party + p1a + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + wave, data = df2, family = "binomial")

# correct order for regression table
vars.order <- c("understand_d1", "ideology_leftright", "ideology_lr_extr", "trust_pol", "trust_party", "p1a", "health_all", "eco_vul", "age", "age2", "child", "marital_d", "covid19", "engaged_if_others", "trust_soc", "sexFemale", "educationmiddel", "educationhigh", "economic_situation_num", "east_d")


```

```{r, results='asis', warning=FALSE, message=FALSE}

model_list <- list(m1, m2, m3, m4)

stargazer2(model_list,
          type="latex",
          single.row = T,
          digits=2,
          odd.ratio = T,
          digits.extra = 0,
          title="Regression Results (odds ratios)",
          column.sep.width = "5pt",
          covariate.labels=c("Sympathy", "Ideology left-right", "Extreme ideology", "Distrust in politicians", "Trust in parties", "Freedom restrictions", "Health threat", "Economic threat", "Age","Age²", "Children",  "Married", "Infection (self or close individuals)", "Engaged if others", "Social trust", "Female",  "Education - middle", "Education - high", "Economic situation", "East Germany"),
          dep.var.labels = c("support", "participate", "support", "participate"),
          star.char = c("*", "**", "***"),
          star.cutoffs = c(0.05, 0.01, 0.001),
          notes = c("* p<0.05; ** p<0.01; *** p<0.001"),
          omit = c("wave9", "wave10", "wave11", "wave12", "wave13", "wave14", "wave15", "wave16", "wave17", "wave18", "wave19", "wave20","wave21", "wave22","wave23"),
          header = FALSE,
          notes.append = F,
          order=paste0("^", vars.order , "$")
          )
```


\newpage

# Robustness check: Multilevel models

As robustness checks, we also ran multilevel models despite the small number of upper level clusters (number of waves = 16). However, the intraclass correlation coefficient for both main dependent variables are very low (see graphs 5 and 6): 0.02 for protest sympathy, 0.01 for willingness to protest. We nevertheless estimated multilevel models with random effects at the upper level. The revised appendix includes these (section 11). The results confirm the main findings from our main models. 


## Cluster variance - Protest sympathy

```{r, echo=FALSE, message=FALSE, warning=FALSE}

# calculate null models

fit <- glmer(understand_d ~ (1 | wave), family = binomial("logit"), data = df2)

fita <- glm(understand_d ~ 1, data = df2, family = binomial("logit"))

```

```{r, message=FALSE, warning=FALSE, fig.align='center', fig.show="hold", fig.cap="\\label{fig:icc1}ICC for sympathy", fig.pos="!htp", fig.width=7, fig.height=4}


# rank plot
u0 <- ranef(fit, postVar = TRUE)
u0se <- sqrt(attr(u0[[1]], "postVar")[1, , ])
commid <- as.numeric(rownames(u0[[1]]))
u0tab <- cbind("commid" = commid, "u0" = u0[[1]], "u0se" = u0se)
colnames(u0tab)[2] <- "u0"
u0tab <- u0tab[order(u0tab$u0), ]
u0tab <- cbind(u0tab, c(1:dim(u0tab)[1]))
u0tab <- u0tab[order(u0tab$commid), ]
colnames(u0tab)[4] <- "u0rank"
plot(u0tab$u0rank, 
     u0tab$u0, 
     type = "n", 
     xlab = "u_rank", 
     main="Estimated residuals for all waves, null model for sympathy",
     ylab = "conditional modes of r.e. for comm_id:_cons", 
     ylim = c(-4, 4))
segments(u0tab$u0rank, u0tab$u0 - 1.96*u0tab$u0se, u0tab$u0rank, u0tab$u0 + 1.96*u0tab$u0se)
points(u0tab$u0rank, u0tab$u0, col = "blue")
abline(h = 0, col = "red")
```


\newpage

## Cluster variance - Protest willingness

```{r, echo=FALSE, message=FALSE, warning=FALSE, eval =FALSE}


# calculate null models


fit <- glmer(part_d ~ (1 | wave), family = binomial("logit"), data = df2)


fita <- glm(part_d ~ 1, data = df2, family = binomial("logit"))



```

```{r, message=FALSE, warning=FALSE, fig.align='center', fig.show="hold", fig.cap="\\label{fig:icc1}ICC for willigness to protest", fig.pos="!htp", fig.width=7, fig.height=4}

# rank plot
u0 <- ranef(fit, postVar = TRUE)
u0se <- sqrt(attr(u0[[1]], "postVar")[1, , ])
commid <- as.numeric(rownames(u0[[1]]))
u0tab <- cbind("commid" = commid, "u0" = u0[[1]], "u0se" = u0se)
colnames(u0tab)[2] <- "u0"
u0tab <- u0tab[order(u0tab$u0), ]
u0tab <- cbind(u0tab, c(1:dim(u0tab)[1]))
u0tab <- u0tab[order(u0tab$commid), ]
colnames(u0tab)[4] <- "u0rank"
plot(u0tab$u0rank, u0tab$u0, 
     main="Estimated residuals for all waves, null model for willingness",
     type = "n", 
     xlab = "u_rank", 
     ylab = "conditional modes of r.e. for comm_id:_cons", 
     ylim = c(-4, 4))
segments(u0tab$u0rank, u0tab$u0 - 1.96*u0tab$u0se, u0tab$u0rank, u0tab$u0 + 1.96*u0tab$u0se)
points(u0tab$u0rank, u0tab$u0, col = "blue")
abline(h = 0, col = "red")
```

```{r, echo=FALSE, warning=FALSE, message=FALSE, eval=FALSE}
# calculate ICC (sympathy)

fit00 <- lmer(as.numeric(understand_d) ~ 1 + (1 | wave), data = df2)
performance::icc(fit00)

fit00 <- lmer(as.numeric(understand_d) ~ 1 + (1 | period), data = df2)
performance::icc(fit00)
```

```{r, echo=FALSE, warning=FALSE, message=FALSE, eval=FALSE}

# calculate ICC (participation)

fit00 <- lmer(as.numeric(part_d) ~ 1 + (1 | wave), data = df2)
performance::icc(fit00)

fit00 <- lmer(as.numeric(part_d) ~ 1 + (1 | period), data = df2)
performance::icc(fit00)

```

\newpage

## Multi-level models
 

```{r}
#
mod1 <- glmer(understand_d ~ ideology_leftright + ideology_lr_extr + trust_gov + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + (1 | wave), data = df2, family = "binomial")

#
mod2 <- glmer(part_d ~ understand_d + ideology_leftright + ideology_lr_extr + trust_gov + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + (1 | wave), data = df2, family = "binomial")

# 
mod3 <- glmer(understand_d ~ ideology_leftright + ideology_lr_extr + p1a + trust_gov + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + (1 | wave), data = df2, family = "binomial")

#
mod4 <- glmer(part_d ~ understand_d + ideology_leftright + ideology_lr_extr + trust_gov + p1a + health_all + eco_vul + age + age2 + child + marital_d + covid19 + engaged_if_others + trust_soc + sex + education + economic_situation_num + east_d + (1 | wave), data = df2, family = "binomial")
```



```{r}

mod1_margins <- margins(mod1)
mod2_margins <- margins(mod2)
mod3_margins <- margins(mod3)
mod4_margins <- margins(mod4)


models_out <- list(
  "Sympathy" =  mod1_margins,
  "Willingness" =  mod2_margins,
  "Sympathy" =  mod3_margins,
  "Willingness" =  mod4_margins)

modelsummary(models_out,
             coef_rename = c("understand_d1" = "Sympathy", "ideology_leftright" = "Ideology left-right",
                             "ideology_lr_extr" = "Extreme ideology", "trust_gov" = "Distrust in government",
                             "p1a" = "Freedom restrictions", "health_all" = "Health threat", 
                             "eco_vul" = "Economic threat", "age" = "Age", "age2" = "Age squ.", 
                             "child" = "Children", "marital_d" = "Married", "understand_d" = "Sympathy", 
                             "covid19" = "Infection (self or close individuals)", 
                             "engaged_if_others" = "Engaged if others", "east_d" = "East Germany", 
                             "trust_soc" = "Social trust", "sexFemale" = "Female", 
                             "educationmiddel" = "Education - middle", "educationhigh" = "Education - high", 
                             "economic_situation_num" = "Economic situation"),
             stars = TRUE,
             coef_omit = "wave*",
             output = "markdown")

```


